package com.itheima.health.controller;

import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "菜单模块管理")
@RequestMapping("menu")
public class MenuController {

    @Reference
    private MenuService menuService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有",notes = "查询所有菜单信息")
    public Result findAll(){
        return new Result(menuService.list());
    }

    @GetMapping("findMenuTree")
    @ApiOperation(value = "查询所有",notes = "按树结构查询所有菜单信息")
    public Result findMenuTree(){
        return new Result(menuService.findMenuTree());
    }

    @PostMapping("findPage")
    @ApiOperation(value = "分页查询",notes = "分页查询菜单列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(menuService.findPage(queryPageBean));
    }

    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "添加或更新菜单模块",notes = "带id过来就更新菜单，不带id过来就是添加菜单功能")
    public Result saveOrUpdate(@RequestBody Menu menu) {
        Boolean flag = menuService.saveOrUpdate(menu);
        return new Result(flag);
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "删除功能",notes = "根据菜单id删除人员信息")
    public Result deleteById(@PathVariable("id") int id){
        Boolean flag =menuService.deleteById(id);
        return new Result(flag);
    }

}
